package com.fulihui.information.core.repository.impl;

import com.fulihui.information.biz.conv.ContentCommentsReplyConv;
import com.fulihui.information.core.repository.ContentCommentsReplyRepository;
import com.fulihui.information.dal.dataobj.InfoContentCommentsReply;
import com.fulihui.information.dal.dataobj.InfoContentCommentsReplyExample;
import com.fulihui.information.dal.mapper.InfoContentCommentsReplyMapper;
import com.fulihui.information.dto.InfoContentCommentsReplyDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.fulihui.information.enums.ECommentsStatus.DELETE;

/**
 * Created by LM on 2017/4/9.
 */
@Repository
public class ContentCommentsReplyRepositoryImpl implements ContentCommentsReplyRepository {

    @Autowired
    private InfoContentCommentsReplyMapper commentsReplyMapper;

    @Override
    public boolean create(InfoContentCommentsReply infoContentCommentsReply) {
        return commentsReplyMapper.insertSelective(infoContentCommentsReply) > 0;
    }

    @Override
    public boolean update(InfoContentCommentsReply infoContentCommentsReply) {
        return commentsReplyMapper.updateByPrimaryKeySelective(infoContentCommentsReply) > 0;
    }

    @Override
    public List<InfoContentCommentsReplyDTO> queryPage(InfoContentCommentsReplyExample example) {
        return ContentCommentsReplyConv.toDTOList(commentsReplyMapper.selectByExample(example));
    }

    @Override
    public long countByExample(InfoContentCommentsReplyExample example) {
        return commentsReplyMapper.countByExample(example);
    }

    @Override
    public InfoContentCommentsReplyDTO selectByPrimaryKey(String id) {
        return ContentCommentsReplyConv.toDTO(commentsReplyMapper.selectByPrimaryKey(id));
    }

    @Override
    public boolean removeByCommentsId(String commentsId) {
        InfoContentCommentsReply record = new InfoContentCommentsReply();
        record.setStatus(DELETE.getCode());
        InfoContentCommentsReplyExample example = new InfoContentCommentsReplyExample();
        example.createCriteria().andCommentIdEqualTo(commentsId);
        return commentsReplyMapper.updateByExampleSelective(record, example) > 0;
    }

}
